package util;

import java.io.ByteArrayOutputStream;

public class MyByteArrayOutputStream extends ByteArrayOutputStream {

	@Override
	public void reset() {
		super.reset();
		buf = new byte[]{}; //�ֶ�������ڴ� 
	}

	@Override
	public void write(byte[] b, int off, int len) {
		super.write(b, off, len);
	}

	@Override
	public byte[] toByteArray() {
		return super.toByteArray();
	}
	
	public byte[] getByteArray(){
		return super.buf;
	}
	
	public void removePreData(int startindex,int length){
		int expEndIndex = startindex + length;
		if (expEndIndex > count)
			throw new ArrayIndexOutOfBoundsException("startindex:"+ startindex+" length:"+length+" above length:"+length);
		System.arraycopy(buf, startindex, buf, 0, length);
		count=length;
	}
	
	public static void main(String[] args) throws Exception{
		MyByteArrayOutputStream output = new MyByteArrayOutputStream();
		output.write(new byte[]{48,49,50});
		output.removePreData(2, 1);
		System.out.println(output.toByteArray());
	}
	
	@Override
	public int size() {
		return super.size();
	}
}
